<?php
/**
 * Created by PhpStorm.
 * User: jimmyhsu
 * Date: 2016/10/12
 * Time: 下午3:27
 */
$name = $_POST['name'];
$deviceid = $_POST['deviceid'];
$itemid = $_POST['itemno'];
include ("conn.php");
$sql = "select * from userinfo where name='$name' and deviceid='$deviceid'";
$rs = mysql_query($sql);
if (mysql_num_rows($rs) == 0) {
    die("invalid user");
}
$sql = "select * from secondhandtb where id=$itemid";
$sqlcomment = "select * from commenttb where attachedtype=2 and attachedid=$itemid";
$rs = mysql_query($sql);
$rscomment = mysql_query($sqlcomment);
$row = mysql_fetch_array($rs);
$commentArr = array();
while ($rowComment = mysql_fetch_array($rscomment)) {
    array_push($commentArr, array("name"=>$rowComment['name'], "time"=>$rowComment['time'],
        "userhead"=>$rowComment['userhead'], "content"=>$rowComment['content']));
}
$result = array("status"=>200, "id"=>$row['id'], "name"=>urlencode($row['username']), "price"=>$row['price'], "time"=>$row['time'],
    "urls"=>urlencode($row['imageurls']), "userimage"=>$row['userimage'], "title"=>urlencode($row['title']), "content"=>urlencode($row['description']),
    "count"=>$row['count'], "condition"=>$row['itemcondition'], "postage"=>$row['postage'], "link"=>$row['link'], "comment"=>$commentArr);
echo urldecode(json_encode($result));

